// Copyright (c), 2006, adopus consulting GmbH Switzerland, all rights reserved.
package com.purej.ui;

import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.factories.Borders;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * Defines a button panel with an OK and Cancel button that usually gets displayed
 * on the bottom of a dialog.
 *
 * @author Stefan Mueller
 */
public final class ButtonPanel {
  private JPanel _panel;
  private JButton _okButton;
  private JButton _cancelButton;

  /**
   * Creates a new instance of this class.
   */
  public ButtonPanel() {
    super();
    _okButton = new JButton("Ok");
    _cancelButton = new JButton("Cancel");
    createUI();
  }

  private void createUI() {
    FormLayout layout = new FormLayout(// JGoodies
        "pref:grow, pref, 4dlu, pref", // 4 columns
        "pref, 7dlu, pref" // 3 rows
    );
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.DIALOG);
    CellConstraints cc = new CellConstraints();

    builder.addSeparator("", cc.xyw(1, 1, 4));
    builder.add(_okButton, cc.xy(2, 3));
    builder.add(_cancelButton, cc.xy(4, 3));
    _panel = builder.getPanel();
  }

  /**
   * @return the button panel
   */
  public JPanel getPanel() {
    return _panel;
  }

  /**
   * @return the ok button
   */
  public JButton getOkButton() {
    return _okButton;
  }

  /**
   * @return the cancel button
   */
  public JButton getCancelButton() {
    return _cancelButton;
  }
}
